package com.jerry.base.io.read;

import com.jerry.base.io.entity.Dog;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;

import java.io.*;

/**
 * Created with IntelliJ IDEA
 * User: Jerry
 * Date: 2024/1/27
 * Time: 15:50
 * Description:
 */
@Slf4j
public class ObjectInputStreamUsage {

    @Test
    public void read() throws IOException, ClassNotFoundException {
        String filePath = "src/main/resources/io/dog.dat";

        try (ObjectInputStream inputStream = new ObjectInputStream(new FileInputStream(filePath))) {
            Dog dog = (Dog) inputStream.readObject();
            log.info(dog.toString());

            byte[] bytes = new byte[2];
            inputStream.read(bytes, 0, bytes.length);
            log.info("bytes: {} ", bytes);
            log.info("byte: {} ", inputStream.readByte());
            log.info("int: {}", inputStream.readInt());
            log.info("long: {}", inputStream.readLong());
            log.info("double: {} ", inputStream.readDouble());
            log.info("boolean: {} ", inputStream.readBoolean());
            log.info("UTF: {}", inputStream.readUTF());
        }
    }
}
